package org.noote.libs.shaky.comm;

public class BluetoothCommandProtocol {

	//////////////////////////////////
	///
	/// Only for Shaky Arduino Sketch 0.3 !
	///
	/////////////////////////////////
	static final String CMD_START_TRAME = "#";
	static final String CMD_END_TRAME = "$";
	protected static String _bounding(String sCmd)
	{
		return CMD_START_TRAME+sCmd+CMD_END_TRAME;
	}
	
	/////////////////////////////////
	// Connect
	static final String CMD_CONNECT = "c";
	public static String sendAskConnection()
	{
		return _bounding(CMD_CONNECT);
	}
	
	/////////////////////////////////
	// Version
	static final String CMD_VERSION = "v";
	public static String sendAskVersion()
	{
		return _bounding(CMD_VERSION);
	}
	
	/////////////////////////////////
	// Servo
	static final String CMD_SERVO = "s";
	public static String sendServoPosition(int idx, int pos)
	{
		return _bounding(CMD_SERVO+intToString(idx)+intToString(pos));
	}

	/////////////////////////////////
	// Servos Position
	static final String CMD_SERVOPOSITION = "p";
	public static String sendServoPositions(int iOffset, int nServos, int []servos_id, int []servos_pos)
	{
		String build="";
		for(int i=0; i<nServos; i++)
		{
			build += intToString(servos_id[iOffset+i]);
			build += intToString(servos_pos[iOffset+i]);
		}
		return _bounding(CMD_SERVOPOSITION+intToString(nServos)+build);
	}
	
	
	/////////////////////////////////
	// tools
	static String intToString(int i)
	{
		String s = Integer.toString(i);
		if(i>=0) s = "+"+s;
		return s;
	}
}
